package com.binge.test6;

import javax.swing.*;
import java.awt.*;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

/**
 * ClassName:Main
 * Package:com.binge.test6
 * Description:
 *
 * @Author @Bin
 * @Date 2023/12/27-10:21
 * @Version: v1.0
 */
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入监测频率,输入为数字，单位为分钟:");
        int i = scanner.nextInt();

        do {
            createAndShowPopup();
            try {
                TimeUnit.MINUTES.sleep(i);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }while (true);


    }

    private static void createAndShowPopup() {
        JFrame frame = new JFrame();
        frame.setAlwaysOnTop(true);
        frame.setUndecorated(true);
        frame.getContentPane().setBackground(new Color(47, 164, 103, 255));
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setSize(300, 150);
        // 创建一个标签显示提示语句
        JLabel label = new JLabel("休息一下", SwingConstants.CENTER);
        label.setForeground(Color.WHITE); // 设置文字颜色
        label.setFont(new Font("Arial", Font.BOLD, 25)); // 设置文字大小
        frame.add(label);
        // 设置窗口位置在屏幕右上角
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();
        frame.setLocation(screenSize.width - frame.getWidth(), 0);
        frame.setVisible(true);
        try {
            TimeUnit.MINUTES.sleep(5);
            frame.dispose();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
